<?php

namespace app\admin\model;

use think\Model;
use traits\model\SoftDelete;

class Studentcontroller extends Model
{
    use SoftDelete;

    // 表名
    protected $name = 'student';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'sex_text',
        'status_text'
    ];

    public function getSexList()
    {
        return ['男' => __('男'), '女' => __('女'), '其他' => __('其他')];
    }

    public function getStatusList()
    {
        return ['在读' => __('在读'), '毕业' => __('毕业'), '休学中' => __('休学中')];
    }


    public function getSexTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['sex']) ? $data['sex'] : '');
        $list = $this->getSexList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function clazz(){
        return $this->belongsTo('Clazzcontroller','clazz_id','id')->setEagerlyType(0);
    }
}
